﻿using System;
using Core.ActionLatencyRealization;
using Core.ProcessManager.Messenger;
using Core.ProcessManager.Process;
using System.Xml.Serialization;

namespace Core.Process
{
    [Serializable]
    [XmlRoot("Action")]
    public class StandartAction : IAction
    {
        [XmlElement]
        public string Name { get; set; } // Название действия
         [XmlElement]
        public byte Level { get; set; }
         [XmlElement]
        public string InitialMessage { get; set; }
         [XmlElement]
         public string FinalMessage { get; set; }
         [XmlElement]
        public int ExecutionTime { get; set; } // Время выполнения

        [return: XmlIgnore]
        public bool Execute(object messengerObj)
        {
            var messenger = (IMessenger)messengerObj;
            var timerWrapper = new TimerWrapper(ExecutionTime, 20);

            //Выполнение действия
            messenger.MessengerState = messenger.CreateNewState(Name, InitialMessage, 0);
            
            timerWrapper.OnTimerTick += messenger.ChangeProgressStatus;
            timerWrapper.Start();

            messenger.ChangeStateMessage(FinalMessage);
            return true;
        }
    }
}